added SSCLI 1.0
[windows-sources.git] / shared source / sscli20 / jscript / engine / jscriptexception.cs
blob33709ba29242da3b8280b36574886477733911c3
1 // ==++==
2 //
3 //
4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
5 //
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
10 //
11 // You must not remove this notice, or any other, from this software.
12 //
13 //
14 // ==--==
16 namespace Microsoft.JScript{
18 using Microsoft.JScript.Vsa;
19 using System;
20 using System.Runtime.InteropServices;
21 using System.Runtime.Serialization;
22 using System.Resources;
23 using System.Security.Permissions;
24 using System.Globalization;
25 using Microsoft.Vsa;
26 using System.Text;
28 //-------------------------------------------------------------------------------------------------------
29 // JScriptException
31 // An error in JScript goes to a CLR host/program in the form of a JScriptException. However a
32 // JScriptException is not always thrown. In fact a JScriptException is also a IVsaError and thus it can be
33 // passed to the host through IVsaSite.OnCompilerError(IVsaError error).
34 // When a JScriptException is not a wrapper for some other object (usually either a COM+ exception or
35 // any value thrown in a JScript throw statement) it takes a JSError value.
36 // The JSError enum is defined in JSError.cs. When introducing a new type of error perform
37 // the following four steps:
38 // 1- Add the error in the JSError enum (JSError.cs)
39 // 2- Update GetErrorType() to return a value from the ErrorType enum (in ErrorConstructor) for the
40 // error you just defined. GetErrorType() is a map form JSError to a JScript object in the Error
41 // hierarchy
42 // 3- Update Microsoft.JScript.txt with the US English error message
43 // 4- Update Severity.
44 //-------------------------------------------------------------------------------------------------------
45 [Serializable] public class JScriptException : ApplicationException, IVsaFullErrorInfo{
46 internal Object value;
47 [NonSerialized] internal Context context;
48 internal bool isError;
49 internal static readonly String ContextStringDelimiter = ";;";
50 private int code; // This is same as base.HResult. We have this so that the debuugger can get the
51 // error code without doing a func-eval ( to evaluate the HResult property )
53 // We don't expect this to be called usually, but add it in case of serialization.
54 public JScriptException()
55 :this(JSError.NoError){
58 public JScriptException(string m)
59 :this(m, null){
62 public JScriptException(string m, Exception e)
63 :this(m, e, null){
66 public JScriptException(JSError errorNumber)
67 :this(errorNumber, null){
70 internal JScriptException(JSError errorNumber, Context context){
71 this.value = Missing.Value;
72 this.context = context;
73 this.code = this.HResult = unchecked((int)(0x800A0000 + (int)errorNumber));
76 internal JScriptException(Object value, Context context){
77 this.value = value;
78 this.context = context;
79 this.code = this.HResult = unchecked((int)(0x800A0000 + (int)JSError.UncaughtException));
82 internal JScriptException(Exception e, Context context) : this(null, e, context){
85 internal JScriptException(string m, Exception e, Context context) : base(m, e){
86 this.value = e;
87 this.context = context;
88 if (e is StackOverflowException){
89 this.code = this.HResult = unchecked((int)(0x800A0000 + (int)JSError.OutOfStack));
90 this.value = Missing.Value;
91 }else if (e is OutOfMemoryException){
92 this.code = this.HResult = unchecked((int)(0x800A0000 + (int)JSError.OutOfMemory));
93 this.value = Missing.Value;
95 else {
96 int hr = System.Runtime.InteropServices.Marshal.GetHRForException(e);
97 if ((hr & 0xffff0000) == 0x800A0000 && System.Enum.IsDefined(typeof(JSError), hr & 0xffff)){
98 this.code = this.HResult = hr;
99 this.value = Missing.Value;
100 }else
101 this.code = this.HResult = unchecked((int)(0x800A0000 + (int)JSError.UncaughtException));
105 protected JScriptException(SerializationInfo info, StreamingContext context)
106 : base(info, context){
107 this.code = this.HResult = info.GetInt32("Code");
108 this.value = Missing.Value;
109 this.isError = info.GetBoolean("IsError");
112 public String SourceMoniker{
113 [PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
114 get{
115 if (this.context != null)
116 return this.context.document.documentName;
117 else
118 return "no source";
122 public int StartColumn{
123 [PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
124 get{
125 return this.Column;
129 public int Column{
130 get{
131 if (this.context != null)
132 return this.context.StartColumn + this.context.document.startCol + 1;
133 else
134 return 0;
138 // We have this method simply to have the same link demand on it as the interface
139 // method has and avoid a FXCOP warning. The Description property itself cannot have
140 // a link demand on it since it is used by the JScript Error object's Description property
141 string IVsaError.Description{
142 [PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
143 get{
144 return this.Description;
148 public string Description{
149 get{
150 return this.Message;
154 public int EndLine{
155 get{
156 if (this.context != null)
157 return this.context.EndLine + this.context.document.startLine - this.context.document.lastLineInSource;
158 else
159 return 0;
163 public int EndColumn{
164 [PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
165 get{
166 if (this.context != null)
167 return this.context.EndColumn + this.context.document.startCol + 1;
168 else
169 return 0;
173 // We have this method simply to have the same link demand on it as the interface
174 // method has and avoid a FXCOP warning. The Number property itself cannot have
175 // a link demand on it since it is used by the JScript Error object's Number property
176 int IVsaError.Number{
177 [PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
178 get{
179 return this.Number;
183 public int Number{
184 get{
185 return this.ErrorNumber;
189 public int ErrorNumber{
190 get{
191 return this.HResult;
195 internal ErrorType GetErrorType(){
196 int ec = this.HResult;
197 if ((ec & 0xFFFF0000) != 0x800A0000) return ErrorType.OtherError;
198 switch ((JSError)(ec & 0xFFFF)){
199 case JSError.AbstractWithBody : return ErrorType.SyntaxError;
200 case JSError.AmbiguousConstructorCall : return ErrorType.ReferenceError;
201 case JSError.AmbiguousMatch : return ErrorType.ReferenceError;
202 case JSError.ArrayLengthConstructIncorrect : return ErrorType.RangeError;
203 case JSError.ArrayLengthAssignIncorrect : return ErrorType.RangeError;
204 case JSError.AssemblyAttributesMustBeGlobal : return ErrorType.SyntaxError;
205 case JSError.AssignmentToReadOnly : return ErrorType.ReferenceError;
206 case JSError.BadBreak : return ErrorType.SyntaxError;
207 case JSError.BadContinue : return ErrorType.SyntaxError;
208 case JSError.BadHexDigit : return ErrorType.SyntaxError;
209 case JSError.BadLabel : return ErrorType.SyntaxError;
210 case JSError.BadReturn : return ErrorType.SyntaxError;
211 case JSError.BadSwitch : return ErrorType.SyntaxError;
212 case JSError.BadFunctionDeclaration : return ErrorType.SyntaxError;
213 case JSError.BadPropertyDeclaration : return ErrorType.SyntaxError;
214 case JSError.BadVariableDeclaration : return ErrorType.SyntaxError;
215 case JSError.BooleanExpected : return ErrorType.TypeError;
216 case JSError.CannotInstantiateAbstractClass : return ErrorType.TypeError;
217 case JSError.CannotNestPositionDirective : return ErrorType.SyntaxError;
218 case JSError.CannotReturnValueFromVoidFunction : return ErrorType.TypeError;
219 case JSError.CantAssignThis : return ErrorType.ReferenceError;
220 case JSError.CcInvalidElif : return ErrorType.SyntaxError;
221 case JSError.CcInvalidElse : return ErrorType.SyntaxError;
222 case JSError.CcInvalidEnd : return ErrorType.SyntaxError;
223 case JSError.CcOff : return ErrorType.SyntaxError;
224 case JSError.CircularDefinition : return ErrorType.SyntaxError;
225 case JSError.ClashWithProperty : return ErrorType.SyntaxError;
226 case JSError.ClassNotAllowed : return ErrorType.SyntaxError;
227 case JSError.ConstructorMayNotHaveReturnType : return ErrorType.SyntaxError;
228 case JSError.DateExpected : return ErrorType.TypeError;
229 case JSError.DifferentReturnTypeFromBase : return ErrorType.TypeError;
230 case JSError.DoesNotHaveAnAddress : return ErrorType.ReferenceError;
231 case JSError.DupDefault : return ErrorType.SyntaxError;
232 case JSError.DuplicateMethod : return ErrorType.TypeError;
233 case JSError.DuplicateNamedParameter : return ErrorType.ReferenceError;
234 case JSError.EnumeratorExpected : return ErrorType.TypeError;
235 case JSError.ErrEOF : return ErrorType.SyntaxError;
236 case JSError.ExpectedAssembly: return ErrorType.SyntaxError;
237 case JSError.ExpressionExpected : return ErrorType.SyntaxError;
238 case JSError.FractionOutOfRange : return ErrorType.RangeError;
239 case JSError.FunctionExpected : return ErrorType.TypeError;
240 case JSError.IllegalAssignment : return ErrorType.ReferenceError;
241 case JSError.IllegalChar : return ErrorType.SyntaxError;
242 case JSError.IllegalEval : return ErrorType.EvalError;
243 case JSError.ImpossibleConversion : return ErrorType.TypeError;
244 case JSError.InstanceNotAccessibleFromStatic : return ErrorType.ReferenceError;
245 case JSError.InvalidBaseTypeForEnum : return ErrorType.TypeError;
246 case JSError.InvalidCall : return ErrorType.TypeError;
247 case JSError.InvalidCustomAttribute : return ErrorType.TypeError;
248 case JSError.InvalidCustomAttributeArgument : return ErrorType.TypeError;
249 case JSError.InvalidCustomAttributeClassOrCtor : return ErrorType.TypeError;
250 case JSError.InvalidDebugDirective: return ErrorType.SyntaxError;
251 case JSError.InvalidElse : return ErrorType.SyntaxError;
252 case JSError.InvalidPositionDirective: return ErrorType.SyntaxError;
253 case JSError.InvalidPrototype : return ErrorType.TypeError;
254 case JSError.ItemNotAllowedOnExpandoClass : return ErrorType.SyntaxError;
255 case JSError.KeywordUsedAsIdentifier : return ErrorType.SyntaxError;
256 case JSError.MemberInitializerCannotContainFuncExpr : return ErrorType.SyntaxError;
257 case JSError.MissingConstructForAttributes : return ErrorType.SyntaxError;
258 case JSError.MissingNameParameter : return ErrorType.ReferenceError;
259 case JSError.MoreNamedParametersThanArguments : return ErrorType.ReferenceError;
260 case JSError.MustBeEOL : return ErrorType.SyntaxError;
261 case JSError.MustProvideNameForNamedParameter : return ErrorType.ReferenceError;
262 case JSError.IncorrectNumberOfIndices : return ErrorType.ReferenceError;
263 case JSError.NeedArrayObject : return ErrorType.TypeError;
264 case JSError.NeedCompileTimeConstant : return ErrorType.ReferenceError;
265 case JSError.NeedInterface : return ErrorType.TypeError;
266 case JSError.NeedInstance : return ErrorType.ReferenceError;
267 case JSError.NeedType : return ErrorType.TypeError;
268 case JSError.NestedInstanceTypeCannotBeExtendedByStatic : return ErrorType.ReferenceError;
269 case JSError.NoAt : return ErrorType.SyntaxError;
270 case JSError.NoCatch : return ErrorType.SyntaxError;
271 case JSError.NoCcEnd : return ErrorType.SyntaxError;
272 case JSError.NoColon : return ErrorType.SyntaxError;
273 case JSError.NoComma : return ErrorType.SyntaxError;
274 case JSError.NoCommaOrTypeDefinitionError : return ErrorType.SyntaxError;
275 case JSError.NoCommentEnd : return ErrorType.SyntaxError;
276 case JSError.NoConstructor : return ErrorType.TypeError;
277 case JSError.NoEqual : return ErrorType.SyntaxError;
278 case JSError.NoIdentifier : return ErrorType.SyntaxError;
279 case JSError.NoLabel : return ErrorType.SyntaxError;
280 case JSError.NoLeftParen : return ErrorType.SyntaxError;
281 case JSError.NoLeftCurly : return ErrorType.SyntaxError;
282 case JSError.NoMemberIdentifier : return ErrorType.SyntaxError;
283 case JSError.NonStaticWithTypeName : return ErrorType.ReferenceError;
284 case JSError.NoRightBracket : return ErrorType.SyntaxError;
285 case JSError.NoRightBracketOrComma : return ErrorType.SyntaxError;
286 case JSError.NoRightCurly : return ErrorType.SyntaxError;
287 case JSError.NoRightParen : return ErrorType.SyntaxError;
288 case JSError.NoRightParenOrComma : return ErrorType.SyntaxError;
289 case JSError.NoSemicolon : return ErrorType.SyntaxError;
290 case JSError.NoSuchMember : return ErrorType.ReferenceError;
291 case JSError.NoSuchStaticMember : return ErrorType.ReferenceError;
292 case JSError.NotIndexable : return ErrorType.TypeError;
293 case JSError.NotAccessible : return ErrorType.ReferenceError;
294 case JSError.NotAnExpandoFunction : return ErrorType.ReferenceError;
295 case JSError.NotCollection : return ErrorType.TypeError;
296 case JSError.NotConst : return ErrorType.SyntaxError;
297 case JSError.NotInsideClass : return ErrorType.SyntaxError;
298 case JSError.NoWhile : return ErrorType.SyntaxError;
299 case JSError.NumberExpected : return ErrorType.TypeError;
300 case JSError.ObjectExpected : return ErrorType.TypeError;
301 case JSError.OLENoPropOrMethod : return ErrorType.TypeError;
302 case JSError.OnlyClassesAllowed : return ErrorType.SyntaxError;
303 case JSError.OnlyClassesAndPackagesAllowed : return ErrorType.SyntaxError;
304 case JSError.PackageExpected : return ErrorType.SyntaxError;
305 case JSError.ParamListNotLast : return ErrorType.SyntaxError;
306 case JSError.PrecisionOutOfRange : return ErrorType.RangeError;
307 case JSError.PropertyLevelAttributesMustBeOnGetter : return ErrorType.ReferenceError;
308 case JSError.RegExpExpected : return ErrorType.TypeError;
309 case JSError.RegExpSyntax : return ErrorType.SyntaxError;
310 case JSError.ShouldBeAbstract : return ErrorType.SyntaxError;
311 case JSError.StaticMissingInStaticInit : return ErrorType.SyntaxError;
312 case JSError.StaticRequiresTypeName : return ErrorType.ReferenceError;
313 case JSError.StringExpected : return ErrorType.TypeError;
314 case JSError.SuperClassConstructorNotAccessible : return ErrorType.ReferenceError;
315 case JSError.SyntaxError : return ErrorType.SyntaxError;
316 case JSError.TooFewParameters : return ErrorType.TypeError;
317 case JSError.TooManyTokensSkipped : return ErrorType.SyntaxError;
318 case JSError.TypeCannotBeExtended : return ErrorType.ReferenceError;
319 case JSError.TypeMismatch : return ErrorType.TypeError;
320 case JSError.UndeclaredVariable : return ErrorType.ReferenceError;
321 case JSError.UndefinedIdentifier : return ErrorType.ReferenceError;
322 case JSError.UnexpectedSemicolon : return ErrorType.SyntaxError;
323 case JSError.UnreachableCatch : return ErrorType.SyntaxError;
324 case JSError.UnterminatedString : return ErrorType.SyntaxError;
325 case JSError.URIEncodeError : return ErrorType.URIError;
326 case JSError.URIDecodeError : return ErrorType.URIError;
327 case JSError.VBArrayExpected : return ErrorType.TypeError;
328 case JSError.WriteOnlyProperty : return ErrorType.ReferenceError;
329 case JSError.WrongDirective : return ErrorType.SyntaxError;
330 case JSError.BadModifierInInterface : return ErrorType.SyntaxError;
331 case JSError.VarIllegalInInterface : return ErrorType.SyntaxError;
332 case JSError.InterfaceIllegalInInterface : return ErrorType.SyntaxError;
333 case JSError.NoVarInEnum : return ErrorType.SyntaxError;
334 case JSError.EnumNotAllowed: return ErrorType.SyntaxError;
335 case JSError.PackageInWrongContext: return ErrorType.SyntaxError;
336 case JSError.CcInvalidInDebugger: return ErrorType.SyntaxError;
337 case JSError.TypeNameTooLong: return ErrorType.SyntaxError;
339 return ErrorType.OtherError;
342 [SecurityPermission(SecurityAction.Demand, SerializationFormatter=true)]
343 public override void GetObjectData(SerializationInfo info, StreamingContext context) {
344 if (info == null) throw new ArgumentNullException("info");
345 base.GetObjectData(info, context);
346 info.AddValue("IsError", this.isError);
347 info.AddValue("Code", this.code);
350 public int Line{
351 [PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
352 get{
353 if (this.context != null)
354 return this.context.StartLine + this.context.document.startLine - this.context.document.lastLineInSource;
355 else
356 return 0;
360 public String LineText{
361 [PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
362 get{
363 if (this.context != null)
364 return this.context.source_string;
365 else
366 return "";
370 internal static String Localize(String key, CultureInfo culture){
371 return JScriptException.Localize(key, null, culture);
374 internal static String Localize(String key, String context, CultureInfo culture){
375 try{
376 ResourceManager rm = new ResourceManager("Microsoft.JScript", typeof(JScriptException).Module.Assembly);
377 String localizedString = rm.GetString(key, culture);
378 if (localizedString != null){
379 // locate context/no-context string delimiter
380 int splitAt = localizedString.IndexOf(ContextStringDelimiter);
381 if (splitAt == -1){
382 // there is no context-specific string
383 return localizedString;
384 }else if (context == null){
385 // splitAt is one character past the end of the no-context string
386 return localizedString.Substring(0, splitAt);
387 }else{
388 // splitAt is two characters before the beginning of the context string
389 return String.Format(culture, localizedString.Substring(splitAt+2), context);
392 }catch(MissingManifestResourceException){
394 return key;
397 public override String Message{
398 get{
399 if (this.value is Exception){
400 Exception e = (Exception)this.value;
401 String result = e.Message;
402 if (result != null && result.Length > 0)
403 return result;
404 else{
405 return e.ToString();
408 String code = (this.HResult & 0xFFFF).ToString(CultureInfo.InvariantCulture);
409 CultureInfo culture = null;
410 if (this.context != null && this.context.document != null){
411 VsaEngine engine = this.context.document.engine;
412 if (engine != null)
413 culture = engine.ErrorCultureInfo;
415 if (this.value is ErrorObject){
416 String result = ((ErrorObject)this.value).Message;
417 if (result != null && result.Length > 0)
418 return result;
419 else
420 return Localize("No description available", culture) + ": " + code;
421 }else if (this.value is String){
422 switch (((JSError)(this.HResult & 0xFFFF))){
423 case JSError.CannotBeAbstract :
424 case JSError.Deprecated:
425 case JSError.DifferentReturnTypeFromBase :
426 case JSError.DuplicateName :
427 case JSError.HidesAbstractInBase:
428 case JSError.HidesParentMember :
429 case JSError.InvalidCustomAttributeTarget :
430 case JSError.ImplicitlyReferencedAssemblyNotFound :
431 case JSError.MustImplementMethod :
432 case JSError.NoSuchMember :
433 case JSError.NoSuchType :
434 case JSError.NoSuchStaticMember :
435 case JSError.NotIndexable :
436 case JSError.TypeCannotBeExtended :
437 case JSError.TypeMismatch :
438 case JSError.InvalidResource:
439 case JSError.IncompatibleAssemblyReference:
440 case JSError.InvalidAssemblyKeyFile:
441 case JSError.TypeNameTooLong:
442 return Localize(code, (String)this.value, culture);
443 default : return (String)this.value;
446 // special case some errors with contextual information
447 if (this.context != null){
448 switch (((JSError)(this.HResult & 0xFFFF))){
449 case JSError.AmbiguousBindingBecauseOfWith :
450 case JSError.AmbiguousBindingBecauseOfEval :
451 case JSError.AssignmentToReadOnly :
452 case JSError.DuplicateName :
453 case JSError.InstanceNotAccessibleFromStatic :
454 case JSError.KeywordUsedAsIdentifier :
455 case JSError.NeedInstance :
456 case JSError.NonStaticWithTypeName :
457 case JSError.NotAccessible :
458 case JSError.NotDeletable :
459 case JSError.NotMeantToBeCalledDirectly :
460 case JSError.ObjectExpected :
461 case JSError.StaticRequiresTypeName :
462 case JSError.UndeclaredVariable :
463 case JSError.UndefinedIdentifier :
464 case JSError.VariableLeftUninitialized :
465 case JSError.VariableMightBeUnitialized :
466 return Localize(code, this.context.GetCode(), culture);
469 return Localize(((int)(this.HResult & 0xFFFF)).ToString(CultureInfo.InvariantCulture), culture);
473 public int Severity{
474 [PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
475 get{
476 //guide: 0 == there will be a run-time error if this code executes
477 // 1 == the programmer probably did not intend to do this
478 // 2 == this can lead to problems in the future.
479 // 3 == this can lead to performance problems
480 // 4 == this is just not right.
481 int ec = this.HResult;
482 if ((ec & 0xFFFF0000) != 0x800A0000) return 0;
483 if (!this.isError){
484 switch ((JSError)(ec & 0xFFFF)){
485 case JSError.AmbiguousBindingBecauseOfWith : return 4;
486 case JSError.AmbiguousBindingBecauseOfEval : return 4;
487 case JSError.ArrayMayBeCopied : return 1;
488 case JSError.AssignmentToReadOnly : return 1;
489 case JSError.BadOctalLiteral : return 1;
490 case JSError.BadWayToLeaveFinally : return 3;
491 case JSError.BaseClassIsExpandoAlready : return 1;
492 case JSError.Deprecated : return 2;
493 case JSError.DifferentReturnTypeFromBase : return 1;
494 case JSError.DuplicateName : return 1;
495 case JSError.DupVisibility : return 1;
496 case JSError.GetAndSetAreInconsistent : return 1;
497 case JSError.HidesParentMember : return 1;
498 case JSError.IncompatibleVisibility : return 1;
499 case JSError.KeywordUsedAsIdentifier : return 2;
500 case JSError.NewNotSpecifiedInMethodDeclaration : return 1;
501 case JSError.NotDeletable : return 1;
502 case JSError.NotMeantToBeCalledDirectly : return 1;
503 case JSError.OctalLiteralsAreDeprecated : return 2;
504 case JSError.PossibleBadConversion : return 1;
505 case JSError.PossibleBadConversionFromString : return 4;
506 case JSError.ShouldBeAbstract : return 1;
507 case JSError.StringConcatIsSlow : return 3;
508 case JSError.SuspectAssignment : return 1;
509 case JSError.SuspectLoopCondition : return 1;
510 case JSError.SuspectSemicolon : return 1;
511 case JSError.TooFewParameters : return 1;
512 case JSError.TooManyParameters : return 1;
513 case JSError.UndeclaredVariable : return 3;
514 case JSError.UselessAssignment : return 1;
515 case JSError.UselessExpression : return 1;
516 case JSError.VariableLeftUninitialized : return 3;
517 case JSError.VariableMightBeUnitialized : return 3;
518 case JSError.IncompatibleAssemblyReference : return 1;
521 return 0;
525 public IVsaItem SourceItem{
526 [PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
527 get{
528 if (this.context != null)
529 return this.context.document.sourceItem;
530 else
531 throw new NoContextException();
536 public override String StackTrace{
537 get{
538 if (this.context == null)
539 return this.Message+Environment.NewLine+base.StackTrace;
540 StringBuilder result = new StringBuilder();
541 Context c = this.context;
543 // Append the "filename: line number" error string
544 String fileName = c.document.documentName;
545 if (fileName != null && fileName.Length > 0)
546 result.Append(fileName+": ");
547 CultureInfo culture = null;
548 if (this.context != null && this.context.document != null){
549 VsaEngine engine = this.context.document.engine;
550 if (engine != null)
551 culture = engine.ErrorCultureInfo;
553 result.Append(Localize("Line", culture));
554 result.Append(' ');
555 result.Append(c.StartLine);
556 // report the error
557 result.Append(" - ");
558 result.Append(Localize("Error", culture));
559 result.Append(": ");
560 result.Append(this.Message);
561 result.Append(Environment.NewLine);
563 if (c.document.engine != null){
564 // Append the stack trace
565 Stack callContextStack = c.document.engine.Globals.CallContextStack;
566 for (int i = 0, n = callContextStack.Size(); i < n; i++){
567 CallContext cctx = (CallContext)callContextStack.Peek(i);
568 result.Append(" ");
569 result.Append(Localize("at call to", culture));
570 result.Append(cctx.FunctionName());
571 result.Append(' ');
572 result.Append(Localize("in line", culture));
573 result.Append(": ");
574 result.Append(cctx.sourceContext.EndLine);
577 return result.ToString();
583 [Serializable]
584 public class NoContextException : ApplicationException{
585 public NoContextException() : base(JScriptException.Localize("No Source Context available", CultureInfo.CurrentUICulture)){
588 public NoContextException(string m) : base(m) {
591 public NoContextException(string m, Exception e) : base(m, e) {
594 protected NoContextException(SerializationInfo s, StreamingContext c) : base(s, c) {